package com.lemon.smartsafety.utils.app;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.entity.common.SelectDataI;
import com.lemon.smartsafety.ui.activity.MainActivity;
import com.lemon.smartsafety.ui.activity.bind.BindCompanyListActivity;
import com.lemon.smartsafety.ui.activity.bind.BindGovListActivity;
import com.lemon.smartsafety.ui.activity.common.AddressSelectActivity;
import com.lemon.smartsafety.ui.activity.common.IndustryActivity;
import com.lemon.smartsafety.ui.activity.fire.SettingFireUrlActivity;
import com.lemon.smartsafety.ui.activity.hidden.HiddenListActivity;
import com.lemon.smartsafety.ui.activity.hidden.HiddenMainActivity;
import com.lemon.smartsafety.ui.activity.hidden.HiddenPropActivity;
import com.lemon.smartsafety.ui.activity.safe.data.BuildingCheckItemBuildingListActivity;
import com.lemon.smartsafety.ui.activity.safe.data.SafeDataCollectionBuildingListActivity;
import com.lemon.smartsafety.ui.activity.safe.data.SafeDataCollectionBuildingPropActivity;
import com.lemon.smartsafety.ui.activity.safe.data.SafeDataCollectionBuildingTypeListActivity;
import com.lemon.smartsafety.ui.activity.safe.data.SafeDataCollectionMainActivity;
import com.lemon.smartsafety.ui.activity.safe.data.SafeDataCollectionPanelActivity;
import com.lemon.smartsafety.ui.activity.user.LoginActivity;
import com.lemon.smartsafety.ui.activity.user.SettingUrlActivity;
import com.lemon.smartsafety.ui.activity.voice.RecordVoiceActivity;
import com.lemon.smartsafetynew.ui.activity.user.UserLoginActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.finalteam.galleryfinal.PhotoPreviewActivity;
import cn.finalteam.galleryfinal.model.PhotoInfo;

import static com.thefinestartist.utils.content.ContextUtil.startActivity;

/**
 * Created by Cooliean on 16/1/19.
 */
public class UIHelper {

    /**
     * 通用的
     * 查看照片
     *
     * @param context
     * @param photoInfoList
     */
    public static void showPhotoView(Context context, List<PhotoInfo> photoInfoList, int currentIndex) {
        Intent intent = new Intent(context, PhotoPreviewActivity.class);
        intent.putExtra(PhotoPreviewActivity.PHOTO_LIST, (Serializable) photoInfoList);
        intent.putExtra(PhotoPreviewActivity.CURRENT_ITEM, currentIndex);
        context.startActivity(intent);
    }

    public static void showPhotoView(Context context, PhotoInfo photoInfo) {
        if (null == photoInfo) {
            return;
        }
        List<PhotoInfo> photoInfoList = new ArrayList<>();
        photoInfoList.add(photoInfo);
        Intent intent = new Intent(context, PhotoPreviewActivity.class);
        intent.putExtra(PhotoPreviewActivity.PHOTO_LIST, (Serializable) photoInfoList);
        intent.putExtra(PhotoPreviewActivity.CURRENT_ITEM, 0);
        context.startActivity(intent);
    }


    /**
     * 显示登录界面
     *
     * @param context
     */
    public static void showLoginActivity(Context context) {
        Intent intent = new Intent(context, LoginActivity.class);
        context.startActivity(intent);
    }


    /**
     * 显示设置服务器地址界面
     *
     * @param context
     */
    public static void showUrlSettingActivity(Context context) {
        Intent intent = new Intent(context, SettingUrlActivity.class);
        context.startActivity(intent);
    }


    /**
     * 显示设置消防服务器地址界面
     *
     * @param context
     */
    public static void showFireUrlSettingActivity(Context context) {
        Intent intent = new Intent(context, SettingFireUrlActivity.class);
        context.startActivity(intent);
    }


    /**
     * 显示主界面
     *
     * @param context
     */
    public static void showMainActivity(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        context.startActivity(intent);
    }

    /****************************************************************************************************************
     * 隐患相关
     ****************************************************************************************************************/
    /**
     * 显示隐患主界面
     *
     * @param context
     */
    public static void showHiddenMainActivity(Context context) {
        Intent intent = new Intent(context, HiddenMainActivity.class);
        context.startActivity(intent);
    }

    /**
     * 显示隐患属性界面
     *
     * @param context
     */
    public static void showHiddenPropActivity(Context context) {
        Intent intent = new Intent(context, HiddenPropActivity.class);
        context.startActivity(intent);
    }

    /**
     * 显示隐患属性界面 （带参数传递）
     *
     * @param context
     * @param bundle
     */
    public static void showHiddenPropActivity(Context context, Bundle bundle) {
        Intent intent = new Intent(context, HiddenPropActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    /**
     * 显示隐患一览表
     *
     * @param context
     */
    public static void showHiddenListActivity(Context context) {
        Intent intent = new Intent(context, HiddenListActivity.class);
        context.startActivity(intent);
    }


    /****************************************************************************************************************
     * 安全巡查
     ****************************************************************************************************************/


    /**
     * 显示数据采集员主界面(查找企业界面）
     *
     * @param context
     */
    public static void showSafeDataCollectionMain(Context context) {
        Intent intent = new Intent(context, SafeDataCollectionMainActivity.class);
        context.startActivity(intent);
    }

    /**
     * 显示数据采集员主界面(功能界面）
     *
     * @param context
     * @param bundle
     */
    public static void showSafeDataCollectionMainPanel(Context context, Bundle bundle) {
        Intent intent = new Intent(context, SafeDataCollectionPanelActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }


    /**
     * 显示数据采集员(建筑管理界面）
     *
     * @param context
     * @param bundle
     */
    public static void showSafeDataCollectionBuildingList(Context context, Bundle bundle) {
        Intent intent = new Intent(context, SafeDataCollectionBuildingListActivity.class);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }


    /**
     * 显示数据采集员(建筑属性界面）
     *
     * @param context
     * @param bundle
     */
    public static void showSafeDataCollectionBuildingProp(Context context, Bundle bundle) {
        Intent intent = new Intent(context, SafeDataCollectionBuildingPropActivity.class);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }


    /**
     * 显示数据采集员(建筑场所分类）
     *
     * @param context
     * @param bundle
     */
    public static void showSafeDataCollectionBuildingTypeList(Context context, Bundle bundle) {
        Intent intent = new Intent(context, SafeDataCollectionBuildingTypeListActivity.class);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }


    /**
     * 数据采集员 《检查项目管理》【建筑列表】
     *
     * @param context
     * @param bundle
     */
    public static void showSafeDataCollectionCheckItemBuildingList(Context context, Bundle bundle) {
        Intent intent = new Intent(context, BuildingCheckItemBuildingListActivity.class);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }
    /**
     * 显示录音界面
     *
     * @param context
     */
    public static void showVoiceRecordActivity(Context context,String tag) {
        Bundle bundle = new Bundle();
        bundle.putString("tag", tag);
        Intent intent = new Intent(context, RecordVoiceActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }


    /**
     * 通用的界面跳转方法
     *
     * @param context
     * @param bundle
     * @param clazz
     */
    public static void showActivity(Context context, Bundle bundle, Class clazz) {
        Intent intent = new Intent(context, clazz);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }

    /**
     * 通用的界面跳转方法
     *
     * @param context
     * @param clazz
     */
    public static void showActivity(Context context, Class clazz) {
        showActivity(context, null, clazz);
    }


    /**
     * 显示多选的行业
     *
     * @param context
     * @param oldList
     */
    public static void showIndustryActivity(Context context, List<SelectDataI> oldList) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BundleKey.IS_MULTI_SELECT, true);
        if (oldList != null) {
            bundle.putSerializable(BundleKey.OLD_SELECT_VALUE_LIST, (Serializable) oldList);
        }
        UIHelper.showActivity(context, bundle, IndustryActivity.class);
    }


    /**
     * 显示单选的行业
     *
     * @param context
     * @param oldString
     */
    public static void showIndustryActivity(Context context, String oldString) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BundleKey.IS_MULTI_SELECT, false);
        if (oldString != null) {
            bundle.putString(BundleKey.OLD_SELECT_VALUE, oldString);
        }
        UIHelper.showActivity(context, bundle, IndustryActivity.class);
    }


    /**
     * 显示多选的通讯录
     *
     * @param context
     * @param oldList
     */
    public static void showMultiAddressBookActivity(Context context, List<SelectDataI> oldList) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BundleKey.IS_MULTI_SELECT, true);
        if (oldList != null) {
            bundle.putSerializable(BundleKey.OLD_SELECT_VALUE_LIST, (Serializable) oldList);
        }
        UIHelper.showActivity(context, bundle, AddressSelectActivity.class);
    }


    /**
     * 绑定信息
     */


    /**
     * 政府机构信息绑定
     *
     * @param context
     */
    public static void showGovBindInfo(Context context,String applicationCode, boolean canNew) {
        Bundle bundle = new Bundle();
        bundle.putString(BundleKey.APPLICATION_CODE, applicationCode);
        bundle.putBoolean(BundleKey.CAN_NEW, canNew);
        UIHelper.showActivity(context, bundle, BindGovListActivity.class);
    }

    /**
     * 企业信息绑定
     *
     * @param context
     */
    public static void showComBindInfo(Context context,String applicationCode, boolean canNew) {
        Bundle bundle = new Bundle();
        bundle.putString(BundleKey.APPLICATION_CODE, applicationCode);
        bundle.putBoolean(BundleKey.CAN_NEW, canNew);
        UIHelper.showActivity(context, bundle, BindCompanyListActivity.class);
    }


    // add by Andrew.yin 2017/8/11 begin

    /**
     *
     * @param context

     */
    public static void showLoginActivityNew(Context context) {
        Intent mIntent = new Intent(context, UserLoginActivity.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(mIntent);
    }


    // add by Andrew.yin 2017/8/11 end

}
